package com.zhkj.txg.module.mine.adapter

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.txg.R
import com.zhkj.txg.module.mine.entity.MineCateEntity
import com.zhkj.txg.module.mine.entity.MineOperationEntity
import com.zhkj.txg.module.mine.entity.OperationType

class MineOrderAdapter : BaseQuickAdapter<MineOperationEntity, BaseViewHolder>(R.layout.item_mine_order) {

    override fun convert(helper: BaseViewHolder, item: MineOperationEntity) {
        ContextCompat.getDrawable(context, item.resId)?.let {
            it.setBounds(0, 0, it.intrinsicWidth, it.intrinsicHeight)
            helper.setText(R.id.tvMineOrderTitle, item.name).getView<TextView>(R.id.tvMineOrderTitle)
                .setCompoundDrawablesRelative(null, it, null, null)
        }
        helper.getView<TextView>(R.id.tvMineOrderBadge).visibility =
            if (item.type == OperationType.COMPLETED || item.type == OperationType.SALE || item.badge == 0) View.GONE else View.VISIBLE
        helper.setText(R.id.tvMineOrderBadge, item.badge.toString())
    }
}

class MineServiceAdapter : BaseQuickAdapter<MineOperationEntity, BaseViewHolder>(R.layout.item_mine_servier) {

    override fun convert(helper: BaseViewHolder, item: MineOperationEntity) {
        ContextCompat.getDrawable(context, item.resId)?.let {
//            it.setBounds(0, 0, it.intrinsicWidth, it.intrinsicHeight)
//            helper.setText(R.id.tvMineServiceTitle, item.name).getView<TextView>(R.id.tvMineServiceTitle)
//                .setCompoundDrawablesRelative(null, it, null, null)

            helper.setText(R.id.tvMineServiceTitle, item.name)
                .getView<ImageView>(R.id.tvMineServiceImage).setImageResource(item.resId)
        }
    }
}